/*
 * Copyright (c) 2024 sovity GmbH
 *
 *  This program and the accompanying materials are made available under the
 *  terms of the Apache License, Version 2.0 which is available at
 *  https://www.apache.org/licenses/LICENSE-2.0
 *
 *  SPDX-License-Identifier: Apache-2.0
 *
 *  Contributors:
 *       sovity GmbH - initial API and implementation
 *
 */

package de.sovity.edc.extension.utils;

import lombok.RequiredArgsConstructor;

import java.util.function.Supplier;

@RequiredArgsConstructor
public class Lazy<T> {
    private final Supplier<T> supplier;

    private T tt;

    public synchronized T get() {
        if (tt == null) {
            tt = supplier.get();
        }

        return tt;
    }

    public boolean isInitialized() {
        return tt != null;
    }
}
